<?php

/*Error Codes
 * 
 * 1 = Fatal Database Error
 */
require_once 'conf.inc';
require_once 'logging.php';
$logger = new logger();
$logger->set_log_directory($log_directory);
$logger->set_log_file($log_file);

echo 	'<form enctype="multipart/form-data" action="index.php?sid='.time().'" method="POST">
			<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
			Choose a file to upload: <input name="uploadedfile" type="file" /><br />
			<input type="submit" value="Upload File" />
			</form>
			';

	if(isset($_GET['ecode'])){
		echo "There was an error";
		
	}

	if(isset($_GET['sid'])){
		$sid = mysql_escape_string($_GET['sid']);
		echo basename($_FILES['uploadedfile']['name']);
		echo '<br/>';
		echo $sid;
		$original_file_name = $_FILES['uploadedfile']['name'];
		$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
		echo var_dump($_FILES['uploadedfile']);
			try
			{
				if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
				{
					throw new Exception($_FILES['userfile']['error']);
				}
				else
				{
					
				}
			}
			catch (Exception $e){
				echo $e->getMessage();
				$logger->log("Could not Move file".$e->getMessage(), "Move File");
			}
	}  
	try {
		if(!mysql_connect($server.":".$port, $username, $password))
		{
			throw new Exception("Error Connecting to Database".mysql_error());
		}
		else
		{
			$conn = mysql_connect($server, $username, $password);
		}
		if(!mysql_select_db($database,$conn)){
			throw new Exception(mysql_errno(), $conn);
		}
		
	}
	catch (Exception $e){
		$logger->log($e->getmessage(),"Mysql Error");
		exit();
	}
	$query = "Select * from manufacturer limit 10";
	try{
		if(!$result = mysql_query($query, $conn)){
			throw new Exception(mysql_errno());
		}
	}
	catch (Exception $e){
		echo $e->getMessage().mysql_error();
	}
	while ($row = mysql_fetch_assoc($result)){
		echo $row['name'];
	}

	
?>